<?php


/**
 * @author thankwsx
 * @version 1.0
 * @created 09-六月-2008 20:33:10
 */
class Core_model extends Model
{

	protected $_table;

	public function __construct() {
		parent::Model();
	}

	public function __destruct() {
	}



	/**
	 * 
	 * @param data
	 */
	public function create(array $data) {
		$data['`create`'] = date("Y-m-d H:i:s");
		$this->db->insert($this->_table,$data);
		return $this->db->insert_id();
	}

	/**
	 * 
	 * @param data
	 */
	public function updated(array $data,$id) {
		if(isset($id) && $id != 0) {
			$data['`update`'] = date("Y-m-d H:i:s");
		}
		$this->db->where("id",$id);
		$this->db->update($this->_table,$data);
		return $this->db->affected_rows();
	}

	/**
	 * 查找符合条件的记录数
	 * 
	 * @param search
	 */
	public function num(array $search) {
	}

	/**
	 * 列出所有字段
	 */
	public function listfields() {
		return $this->db->list_fields();
	}

	/**
	 * 
	 * @param field
	 * @param search
	 * @param orderby
	 * @param limit
	 */
	public function retriveby($field = '', $search = array(), $orderby = '', $limit = '1') {
		if(!empty($field)) {
		  $this->db->select($field);
		}
		if(is_array($search) && count($search) != 0) {
		  $this->db->where($search);
		}
		if(!empty($orderby)) {
		  $this->db->orderby($orderby);
		}
		if($limit != '1') {
		  $this->db->limit($limit);
		}
		$result = $this->db->get($this->_table);
		return $result->result_array();
	}

	/**
	 * 
	 * @param id
	 */
	public function findById(int $id) {
		$this->db->where("id",$id);
		$query = $this->db->get($this->_table);
		return $query->row_array();
	}

}
?>